home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 151-175 / disk_160 / m4 / src / mdef.h < prev    next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  201 lines

  1. /*
  2.  * mdef.h
  3.  * Facility: m4 macro processor
  4.  * by: oz
  5.  */
  6. #define unix 1 /* should be here so i don't have to rewrite all the code. */
  7.  
  8. #ifndef unix
  9. #define unix 0
  10. #endif 
  11.  
  12. #ifndef vms
  13. #define vms 0
  14. #endif
  15.  
  16. #if vms
  17.  
  18. #include stdio
  19. #include ctype
  20. #include signal
  21.  
  22. #else 
  23.  
  24. #include <stdio.h>
  25. #include <ctype.h>
  26. #include <signal.h>
  27. #include <stdlib.h>
  28.  
  29. #endif
  30.  
  31. /*
  32.  *
  33.  * m4 constants..
  34.  *
  35.  */
  36.  
  37. #define MACRTYPE        1
  38. #define DEFITYPE        2
  39. #define EXPRTYPE        3
  40. #define SUBSTYPE        4
  41. #define IFELTYPE        5
  42. #define LENGTYPE        6
  43. #define CHNQTYPE        7
  44. #define SYSCTYPE        8
  45. #define UNDFTYPE        9
  46. #define INCLTYPE        10
  47. #define SINCTYPE        11
  48. #define PASTTYPE        12
  49. #define SPASTYPE        13
  50. #define INCRTYPE        14
  51. #define IFDFTYPE        15
  52. #define PUSDTYPE        16
  53. #define POPDTYPE        17
  54. #define SHIFTYPE        18
  55. #define DECRTYPE        19
  56. #define DIVRTYPE        20
  57. #define UNDVTYPE        21
  58. #define DIVNTYPE        22
  59. #define MKTMTYPE        23
  60. #define ERRPTYPE        24
  61. #define M4WRTYPE        25
  62. #define TRNLTYPE        26
  63. #define DNLNTYPE        27
  64. #define DUMPTYPE        28
  65. #define CHNCTYPE        29
  66. #define INDXTYPE        30
  67. #define SYSVTYPE        31
  68. #define EXITTYPE        32
  69. #define DEFNTYPE        33
  70.  
  71. #define STATIC          128
  72.  
  73. /*
  74.  * m4 special characters
  75.  */
  76.  
  77. #define ARGFLAG         '$'
  78. #define LPAREN          '('
  79. #define RPAREN          ')'
  80. #define LQUOTE          '`'
  81. #define RQUOTE          '\''
  82. #define COMMA           ','
  83. #define SCOMMT          '#'
  84. #define ECOMMT          '\n'
  85.  
  86. /*
  87.  * definitions of diversion files. If the name of
  88.  * the file is changed, adjust UNIQUE to point to the
  89.  * wildcard (*) character in the filename.
  90.  */
  91.  
  92. #if unix
  93. #define DIVNAM  "/tmp/m4*XXXXXX"        /* unix diversion files    */
  94. #define UNIQUE          7               /* unique char location    */
  95. #else
  96. #if vms
  97. #define DIVNAM  "sys$login:m4*XXXXXX"   /* vms diversion files     */
  98. #define UNIQUE          12              /* unique char location    */
  99. #else
  100. #if amiga
  101. #define DIVNAM    "t:M4*XXXXXX"        /* msdos diversion files   */
  102. #define    UNIQUE        4            /* unique char location    */
  103. #else
  104. #define DIVNAM    "/M4*XXXXXX"        /* msdos diversion files   */
  105. #define    UNIQUE        3            /* unique char location    */
  106. #endif
  107. #endif
  108. #endif
  109.  
  110. /*
  111.  * other important constants
  112.  */
  113.  
  114. #define EOS             (char) 0
  115. #define MAXINP          10              /* maximum include files   */
  116. #define MAXOUT          10              /* maximum # of diversions */
  117. #define MAXSTR          512             /* maximum size of string  */
  118. #define BUFSIZE         4096            /* size of pushback buffer */
  119. #define STACKMAX        1024            /* size of call stack      */
  120. #define STRSPMAX        4096            /* size of string space    */
  121. #define MAXTOK          MAXSTR          /* maximum chars in a tokn */
  122. #define HASHSIZE        199             /* maximum size of hashtab */
  123.  
  124. #define ALL             1
  125. #define TOP             0
  126.  
  127. #define TRUE            1
  128. #define FALSE           0
  129. #define cycle           for(;;)
  130.  
  131. #ifdef VOID
  132. #define void            int             /* define if void is void. */
  133. #endif
  134.  
  135. /*
  136.  * m4 data structures
  137.  */
  138.  
  139. typedef struct ndblock *ndptr;
  140.  
  141. struct ndblock {                /* hastable structure         */
  142.         char    *name;          /* entry name..               */
  143.         char    *defn;          /* definition..               */
  144.         int     type;           /* type of the entry..        */
  145.         ndptr   nxtptr;         /* link to next entry..       */
  146. };
  147.  
  148. #define nil     ((ndptr) 0)
  149.  
  150. struct keyblk {
  151.         char    *knam;          /* keyword name */
  152.         int     ktyp;           /* keyword type */
  153. };
  154.  
  155. typedef union {            /* stack structure */
  156.     int    sfra;        /* frame entry  */
  157.     char     *sstr;        /* string entry */
  158. } stae;
  159.  
  160. /*
  161.  * macros for readibility and/or speed
  162.  *
  163.  *      gpbc()  - get a possibly pushed-back character
  164.  *      min()   - select the minimum of two elements
  165.  *      pushf() - push a call frame entry onto stack
  166.  *      pushs() - push a string pointer onto stack
  167.  */
  168. #define gpbc()      (bp > buf) ? *--bp : getc(infile[ilevel])
  169. /* #define min(x,y) ((x > y) ? y : x) defined in stdio.h.. */
  170. #define pushf(x) if (sp < STACKMAX) mstack[++sp].sfra = (x)
  171. #define pushs(x) if (sp < STACKMAX) mstack[++sp].sstr = (x)
  172.  
  173. /*
  174.  *        .                   .
  175.  *    |   .    |  <-- sp        |  .  |
  176.  *    +-------+            +-----+
  177.  *    | arg 3 ----------------------->| str |
  178.  *    +-------+            |  .  |
  179.  *    | arg 2 ---PREVEP-----+        .
  180.  *    +-------+          |
  181.  *        .              |        |     |
  182.  *    +-------+          |     +-----+
  183.  *    | plev    |  PARLEV     +-------->| str |
  184.  *    +-------+            |  .  |
  185.  *    | type    |  CALTYP           .
  186.  *    +-------+
  187.  *    | prcf    ---PREVFP--+
  188.  *    +-------+         |
  189.  *    |   .    |  PREVSP  |
  190.  *        .              |
  191.  *    +-------+       |
  192.  *    |    <----------+
  193.  *    +-------+
  194.  *
  195.  */
  196. #define PARLEV  (mstack[fp].sfra)
  197. #define CALTYP  (mstack[fp-1].sfra)
  198. #define PREVEP    (mstack[fp+3].sstr)
  199. #define PREVSP    (fp-3)
  200. #define PREVFP    (mstack[fp-2].sfra)
  201.